package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 订单页的确认页数据
 **/
public class OrderConfirmVo {

    /**
     * 对应的Sku是否有货
     **/
    @Setter
    @Getter
    private Map<Long,Boolean> hasStock;
    /**
     * 订单的防重令牌token
     **/
    @Setter
    @Getter
    private String orderToken;
    /**
     * 收货地址
     **/
    private List<MemberAddressVo> address;
    /**
     * 所有选中的购物项
     **/
    private List<OrderItemVo> items;
    /**
     * 发票记录等等
     **/
    /**
     * 优惠券信息
     **/
    private Integer intergration;
    /**
     * 订单总额
     **/
    private BigDecimal total;
    /**
     * 应付价格
     **/
    private BigDecimal payPrice;

    public Integer getCount() {

        Integer count = 0;
        if (!CollectionUtils.isEmpty(items)) {
            for (OrderItemVo item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public List<MemberAddressVo> getAddress() {
        return address;
    }

    public void setAddress(List<MemberAddressVo> address) {
        this.address = address;
    }

    public List<OrderItemVo> getItems() {
        return items;
    }

    public void setItems(List<OrderItemVo> items) {
        this.items = items;
    }

    public Integer getIntergration() {
        return intergration;
    }

    public void setIntergration(Integer intergration) {
        this.intergration = intergration;
    }

    public BigDecimal getTotal() {
        total = new BigDecimal("0");
        if (!CollectionUtils.isEmpty(items)) {
            for (OrderItemVo item : items) {
                BigDecimal decimal = item.getPrice().multiply(new BigDecimal(item.getCount()));
                total = total.add(decimal);
            }
        }
        return total;
    }

    public BigDecimal getPayPrice() {
        payPrice = new BigDecimal("0");
        if (!CollectionUtils.isEmpty(items)) {
            for (OrderItemVo item : items) {
                BigDecimal decimal = item.getPrice().multiply(new BigDecimal(item.getCount()));
                payPrice = payPrice.add(decimal);
            }
        }
        return payPrice;
    }

}
